package com.zxc.controller.chart;

import com.zxc.entity.CstType;
import com.zxc.service.CstTypeService;
import com.zxc.service.SctServiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/chart/service")
public class CustomerServiceController {

    @Autowired
    private CstTypeService cstTypeService;

    @Autowired
    private SctServiceService sctServiceService;

    @RequestMapping({"/init/{searchYear}","/init"})
    @ResponseBody
    public List<Map<String,Object>> getSctServiceListOrByCustName(
            @PathVariable(required = false) String searchYear){
        List<Map<String,Object>> modelList = new ArrayList<>();
        //查询服务类型表的服务类型
        List<CstType> cstTypeList = cstTypeService.getCstTypeService();

        //根据在服务列表中查询到的服务类型的字段到客户服务表中进行查询
        for (CstType cstType : cstTypeList){
            Map<String,Object> modelMap = new HashMap<>();
            modelMap.put("cstTypeId",cstType.getCstTypeId());
            modelMap.put("typeName",cstType.getTypeName());
            int total = sctServiceService.selectCountSctServiceBySvrType(cstType.getTypeName(),searchYear);
            modelMap.put("total",total);
            modelList.add(modelMap);

        }

        return modelList;
    }


}
